package com.kitchen;

import com.kitchen.mapper.FoodLikeMapper;
import com.kitchen.mapper.FoodMapper;
import com.kitchen.beans.entity.Food;
import com.kitchen.beans.vo.FoodVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class EntityToVO {
    @Autowired
    FoodMapper foodMapper;
    @Autowired
    FoodLikeMapper foodLikeMapper;
    public FoodVO entitytoFoodvo(Food food){
        FoodVO foodVO = new FoodVO();
        if (food.getFImage()!=null){
            String[] images = food.getFImage().split("[|]");
            foodVO.setFIndexImage(images[0]);
            foodVO.setFImages(images);
        }
        BeanUtils.copyProperties(food,foodVO);
        if (food.getFContext()!=null) {
            String[] context = food.getFContext().split("[|]");
            foodVO.setFContexts(context);
        }
        if (food.getFIngredients()!=null) {
            String[] ingredients = food.getFIngredients().split("[|]");
            foodVO.setFIngredients(ingredients);
        }
        if (food.getFKitchenware()!=null) {
            String[] kitchenware = food.getFKitchenware().split("[|]");
            foodVO.setFKitchenwares(kitchenware);
        }
        Food food1 = new Food();
        food1.setFName(food.getFName());
        int count = foodMapper.selectCount(food1);
        foodVO.setNum(count);
        return foodVO;
    }

}
